package com.zhou.listener;


import android.content.Context;
import android.support.annotation.NonNull;
import android.view.ViewGroup;

import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.zhou.listener.bean.KeyGen;
import com.zhou.listener.library.utils.KeyUtils;
import com.zhou.listener.listener.RecyclerDownloadListener;
import com.zhou.listener.utils.AdapterUtils;

import java.util.List;

public class EaseAdapter extends RecyclerArrayAdapter<MyBean> {

    public EaseAdapter(Context context, List<MyBean> objects) {
        super(context, objects);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new EaseViewHolder(parent,R.layout.item2);
    }

    @Override
    public void OnBindViewHolder(BaseViewHolder holder, int position) {
        super.OnBindViewHolder(holder, position);
        EaseViewHolder ev = (EaseViewHolder)holder;
        KeyUtils.addKeyGens(ev,new KeyGen(mObjects.get(position).id+""));
        AdapterUtils.updateListener(ev.keys,new RecyclerDownloadListener(ev));
    }

    @Override
    public void onViewDetachedFromWindow(@NonNull BaseViewHolder holder) {
        super.onViewDetachedFromWindow(holder);
        AdapterUtils.clearPreListener(((EaseViewHolder)holder).keys);
    }
}
